const conn = require('../../libs/DB/Conn');
const operationRecord = require("../sys/operationRecordAction");
module.exports = async function (params) {
    let checkUserSql = `SELECT      
                          count(*) AS count
                        FROM
                          domain_file                        
                        WHERE domain_name = ? AND delete_sign = 1;`;
    let queryResult = await conn(checkUserSql, [params.domainName]);
    if (queryResult[0].count > 0) {
        return {success: false, message: '此区域名称已存在'};
    }else {
        if(params.userAgentId){
            let insertObj = {
                domain_name: params.domainName,
                district_id: params.districtId,
                address: params.address,
                agent_id:params.userAgentId,
                manager_name: params.managerName,
                manager_mobile: params.managerMobile
            };
            let insertSql = `INSERT INTO domain_file SET ?`;
            await conn(insertSql, [insertObj]);
            await operationRecord(params);
            return {success: true}
        }else {
            return {success: false, message: '未找到代理商无法添加'};
        }
    }
};